<template>
  <a-modal
    :title="title"
    :width="800"
    :dialogStyle="{ top: '30px' }"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    :okButtonProps="{ props: { disabled: disableSubmit } }"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-alert message="请慎重选择订单状态。" banner />
        <br />
          <a-form-item   :labelCol="labelCol" :wrapperCol="wrapperCol" label="订单状态">
            <a-select placeholder="请选择订单状态" v-decorator="['orderStatus', validatorRules.orderStatus]"  style="width: 100%" >
              <a-select-option v-for="item in orderStatusList" :key="item.key" :value="item.key">{{ item.val }}</a-select-option>
            </a-select>
          </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import moment from "moment";
  export default {
    name: "OrderFormModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        orderStatusList:[],
        disableSubmit:false,
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
          orderStatus:{
            rules: [{
              required: true, message: '请选择订单状态!'
            }]
          },
        },
        url: {
          add: "/orderForm/orderForm/add",
          edit: "/orderForm/orderForm/editByOrderStatus",
        },
      }
    },
    created () {

    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      setOrderStatusList(obj){
        this.orderStatusList=obj;
      },
      close () {
        this.$emit('ok');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            httpurl+=this.url.edit;
            method = 'put';
            let formData = Object.assign(this.model, values);
            console.log("formData-->",formData);
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })

          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style scoped>

</style>